import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:wanxiang_app/pages/index.dart';
import 'package:wanxiang_app/pages/login/login.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:wanxiang_app/pages/splash.dart';
import 'package:wanxiang_app/utils/constant.dart';
import 'package:wanxiang_app/utils/sp_util.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'l10n/translations.dart';


void main() async{

  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
  SpUtil.getInstance();
  SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(statusBarColor: Colors.transparent,statusBarBrightness:Brightness.dark,statusBarIconBrightness:Brightness.dark));
  await SharedPreferences.getInstance();

  runApp(const MyApp());
}



// class MyApp extends StatelessWidget {
//   const MyApp({super.key});
//
//   // This widget is the root of your application.
//   @override
//   Widget build(BuildContext context) {
//     return MaterialApp(
//       title: 'Flutter Demo',
//       localizationsDelegates: [
//         GlobalCupertinoLocalizations.delegate,
//         GlobalMaterialLocalizations.delegate,
//         GlobalWidgetsLocalizations.delegate,
//       ],
//       locale: Get.deviceLocale,
//       supportedLocales: AppTranslations.supportedLocales,
//       theme: ThemeData(
//         colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
//         useMaterial3: true,
//       ),
//       home: const MyHomePage(title: 'Flutter Demo Home Page'),
//     );
//   }
// }

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);


  @override
  State<MyApp> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyApp> with WidgetsBindingObserver{

@override
  void initState() {

  EasyRefresh.defaultHeaderBuilder = () => ClassicHeader(
    dragText: 'Pull to refresh'.tr,
    armedText: 'Release ready'.tr,
    readyText: 'Refreshing...'.tr,
    processingText: 'Refreshing...'.tr,
    processedText: 'Succeeded'.tr,
    noMoreText: 'No more'.tr,
    failedText: 'Failed'.tr,
    messageText: 'Last updated at %T'.tr,
  );
  EasyRefresh.defaultFooterBuilder = () => ClassicFooter(
    dragText: 'Pull to load'.tr,
    armedText: 'Release ready'.tr,
    readyText: 'Loading...'.tr,
    processingText: 'Loading...'.tr,
    processedText: 'Succeeded'.tr,
    noMoreText: 'No more'.tr,
    failedText: 'Failed'.tr,
    messageText: 'Last updated at %T'.tr,
  );
  WidgetsBinding.instance.addObserver(this);
    super.initState();
  }


  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: Size(360, 640),
      builder: (BuildContext context,
        Widget? child) {
          return GetMaterialApp(
            title: '淘号阁',
              theme: ThemeData(
                splashColor: Colors.transparent, // 点击时的高亮效果设置为透明
                highlightColor: Colors.transparent, // 长按时的扩散效果设置为透明
              ),
              debugShowCheckedModeBanner: false,
              translations: AppTranslations(),
            localizationsDelegates: const[
              GlobalCupertinoLocalizations.delegate,
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
            ],
              locale: Get.deviceLocale,
              fallbackLocale: AppTranslations.fallbackLocale,
              supportedLocales: AppTranslations.supportedLocales,
              builder: BotToastInit(),
              home:Scaffold(
                  backgroundColor: Colors.white,
                body: WelcomePage(),
                // body: IndexPage(),
                  resizeToAvoidBottomInset:false
              )
          );
       },

    );
  }
}
